<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .adver {
            width: 300px;
            /* height: 400px; */
            background-color: aquamarine;
            position: fixed;
            right: 5px;
            bottom: 5px;
            display: none;
            /* display: block; */
        }

        .adver-header {
            overflow: hidden;
            line-height: 20px;
            font-size: 13px;
            padding: 0 5px;
        }

        .adver-header .adver-title {
            float: left;
        }

        .adver-header .adver-close {
            float: right;
        }

        .adver-main img {
            width: 100%;
        }
    </style>
</head>

<body>
    <!-- 操作页面中已有的元素 -->
    <div class="adver">
        <div class="adver-header">
            <div class="adver-title">距离广告关闭还有10秒</div>
            <div class="adver-close">X</div>
        </div>
        <div class="adver-main">
            <img src="../images/bzsc-dgbhz-300-250-7-5.gif" alt="">
        </div>
    </div>
</body>
<script>
    
    var adver = document.getElementsByClassName("adver")[0];
    var adver = document.querySelector(".adver");
    var adverTitle = document.getElementsByClassName("adver-title")[0];
    var adverClose = document.getElementsByClassName("adver-close")[0];

    var timer = null; // 延时器的编号
    var timer1 = null; // 计时器的编号

    showAdver();

    adverClose.onclick = function(){
        clearTimeout(timer);
        clearInterval(timer1);
        adver.style.display = "none"; // 隐藏小广告
        
        showAdver();
    }

    function showAdver() {
        timer = setTimeout(function () {
            adver.style.display = "block"; // 显示小广告

            var count = 10;
            adverTitle.innerText = `距离广告关闭还有${count}秒`;

            timer1 = setInterval(function () {
                count--;
                adverTitle.innerText = `距离广告关闭还有${count}秒`;

                if (count == 0) {
                    clearInterval(timer1);
                    adver.style.display = "none"; // 隐藏小广告

                    showAdver();
                }
            }, 1000);
        }, 5000);
    }






</script>

</html>